{% extends 'homepage.html' %}

{% block content %}
    <!--<div id="header">
        <div class="logo">
            <a href="/Character/Dirichlet">{{ title }} home</a>
        </div>
        <div class="banner">
            <span>The logo of the portal could go here... </span>
        </div>
    </div>-->

<script>
var cur_system = null;
function show_code(system) {
    $('.sage').hide();
    $('.pari').hide();
    $('.magma').hide();
    if (cur_system == null) {
      $('.'+system).show();
      cur_system = system;
    } else {
      $('.'+system).hide();
      cur_system = null;
    }
}
</script>

<style>
.output {
    margin:20px 0;
    text-align: left;
}
table.navi td {
    padding: 0;
}
table.props tr td:first-child {
    width: 5em;
}
#content p, #content form, #content div {
    margin-left: 20px;
}

</style>
        <div align="right">
            <font size="3">Show commands for:</font>
            <a onclick="show_code('sage'); return false" href='#'>sage</a>
        </div>
 
        <div class='sage nodisplay code'>sage: chi = DirichletGroup({{modulus}})[{{number}}]</div>

        {# Kronecker symbol #}

        {% if order|int == 2 %}
        <h2>
            {{ KNOWL('character.dirichlet.kronecker_symbol') }} representation
        </h2>
        <div class = 'sage nodisplay code'>sage: a.kronecker({{conductor}})</div>
        <p>
        {{ kronsymbol }} (mod {{modulus}})
        </p>
        {% endif %}

        {# Induced character #}

        {% if primitive=="False" %}
            <h2>
                Inducing {{ KNOWL('character.dirichlet.induced_character', title="primitive character") }}
            </h2>
            <div class = 'sage nodisplay code'>sage: chi.primitive_character()</div>
            <p>
            <a href="{{ url_for('render_webpage_label', 
                modulus = inducedchar_modulus, 
                number  = inducedchar_number)}}">
                {{inducedchar_tex}}
            </a>
            </p>
        {% endif %}

        {# Values #}
        
        <h2>
            {{ KNOWL('character.dirichlet.values', title="Values") }}
        </h2>
        <div class = 'sage nodisplay code'>sage: chi.values()</div>
        <p>
            {% if root_unity=="True" %} 
                For \(\zeta_{ {{ zetaorder }} }\) a primitive 
                \( {{ zetaorder }} \)-th root of unity
                <br><br/> 
            {% endif %}
        </p>
        <div align="left"> 
            [\({{ valstex|join("\) , \(") }}\)]
        </div>
        
        {# Values on generators #}

        <h2>
            {{ KNOWL('character.dirichlet.values_on_gens', title="Values on generators") }}
        </h2>
        <div class = 'sage nodisplay code'>sage: chi.values_on_gens()</div>
        <p>
            \( {{ unitgens }} \) &rarr; \( {{ genvalstex }} \)
        </p>

        <h2> {{ KNOWL('character.dirichlet.basic_properties', title="Basic properties") }} </h2>

        {# Basic properties #}
        <table class="props">
            <tr>
                <td>
                    <span class='sage nodisplay code'>sage: chi.conductor()</span>
                </td>
            </tr>
            <tr>
                <td>Conductor</td>
                <td>=</td>
                <td>\({{ conductor }}\)</td>
            </tr>
            <tr>
                <td>
                    <span class='sage nodisplay code'>sage: chi.order()</span>
                </td>
            </tr>
            <tr>
                <td> Order </td>
                <td>=</td>
                <td>\({{ order }} \)</td>
            </tr>
            <tr>
                <td>
                    <span class='sage nodisplay code'>sage: chi.is_even() or chi.is_odd()</span>
                </td>
            </tr>
            <tr>
                <td> Parity </td>
                <td>=</td>
                <td> {{ parity }}</td>
            </tr>
            <tr>
                <td> Real </td>
                <td>=</td>
                    {% if sign=="True" %}
                        <td> Yes</td>
                    {% else %}
                        <td> No </td>
                    {% endif %}
            </tr>
            <tr>
                <td>
                    <span class='sage nodisplay code'>sage: chi.is_primitive()</span>
                </td>
            </tr>
            <tr>
                <td> Primitive </td>
                <td>=</td>
                    {% if primitive=="True" %}
                        <td>Yes</td> 
                    {% else %}
                        <td> No</td>  
                    {% endif %}
            </tr>
        </table>
        
        {# Gauss sum #}

        <h2>
            {{ KNOWL('character.dirichlet.gauss_sum') }}
        </h2>
        <div class = 'sage nodisplay code'>sage: chi.gauss_sum()</div>
        {% set gauss_default = 2 %}
        <form> \( \tau_{ a }( \chi_{ {{number}} } )\;\)  at \(\;a = \)
            <input id="calc-gauss-input" size=10 placeholder={{gauss_default}}>
            <button id="calc-gauss-go"> Compute </button>
            <span class="formexample"> e.g. {{gauss_default}} </span>
            <div class="slider" id="slider-gauss"></div>
        </form>
        <div class="output"><span id="calc-gauss-output"></span></div>

        {# Jacobi sum #}

        <h2>
            {{ KNOWL('character.dirichlet.jacobi_sum') }}
        </h2>
        <div class = 'sage nodisplay code'>sage: chi.jacobi_sum()</div>
        {% set jacobi_default = 1 %}
        <form> \( J(\chi_{ {{number}} },\psi) \;\) for \( \;\psi = {{modulus}}.\)
            <input id="calc-jacobi-input" size="10" placeholder={{jacobi_default}}>
            <button id="calc-jacobi-go"> Compute </button>
            <span class="formexample"> n.b., takes values 0--{{eulerphi}}</span>
            <div class="slider" id="slider-jacobi-b"></div>
        </form>
        <div class="output"><span id="calc-jacobi-output"></span></div>
        
        {# Kloosterman sum #}

        <h2>
            {{ KNOWL('character.dirichlet.kloosterman_sum') }}
        </h2>
        <div class = 'sage nodisplay code'>sage: chi.kloosterman_sum(,)</div>
        {% set kloosterman_default_a = 1 %}
        {% set kloosterman_default_b = 2 %} 
        <form> \(K(a,b,\chi_{ {{number}} }) \;\) at \(\; a,b = \)
            <input id="calc-kloosterman-input" size=10 placeholder={{kloosterman_default_a}},{{kloosterman_default_b}}>
            <button id="calc-kloosterman-go"> Compute </button>
            <span class="formexample"> e.g. {{kloosterman_default_a}},{{kloosterman_default_b}}</span>
            <div class="slider" id="slider-kloosterman-a"></div>
            <div class="slider" id="slider-kloosterman-b"></div>
        </form>
        <div class="output"><span id="calc-kloosterman-output"></span></div>

<script type="text/javascript">
function gauss_handler(evt) {
    evt.preventDefault();
    var val = $("#calc-gauss-input").val();
    $("#calc-gauss-output").load("{{ url_for('dc_calc_gauss', modulus=modulus,number=number) }}" + "?val=" + val, 
     function() {
        {# tell mathjx to render the output #}
        MathJax.Hub.Queue(['Typeset', MathJax.Hub, "calc-gauss-output"]);
     });
}
function jacobi_handler(evt) {
   evt.preventDefault();
   var val = $("#calc-jacobi-input").val();
   $("#calc-jacobi-output").load("{{ url_for('dc_calc_jacobi', modulus=modulus,number=number) }}" + "?val=" + val,
     function() {
       {# tell mathjx to render the output #}
       MathJax.Hub.Queue(['Typeset', MathJax.Hub, "calc-jacobi-output"]);
     });
}

function kloosterman_handler(evt) {
   evt.preventDefault();
   var val = $("#calc-kloosterman-input").val();
   $("#calc-kloosterman-output").load("{{ url_for('dc_calc_kloosterman', modulus=modulus,number=number) }}" + "?val=" + val,
     function() {
       {# tell mathjx to render the output #}
       MathJax.Hub.Queue(['Typeset', MathJax.Hub, "calc-kloosterman-output"]);
     });
}

$(function() {
    $("#calc-gauss-go").click(function(e) {gauss_handler(e)});
    $("#calc-jacobi-go").click(function(e) {jacobi_handler(e)});
    $("#calc-kloosterman-go").click(function(e) {gauss_handler(e)});
    $("#calc-gauss-input").keypress(function(e) {
        if (e.which == 13) gauss_handler(e);
        });
    {#$("#calc-gauss-input").ready(function(e) {
        gauss_handler(e);
        });#}
    $("#calc-jacobi-input").keypress(function(e) {
        if (e.which == 13) jacobi_handler(e);
    });
    $("#calc-kloosterman-input").keypress(function(e) {
        if (e.which == 13) kloosterman_handler(e);
    });

    {#{$( "#slider-gauss-default" ).slider({ value:2,
        create: function( event, ui ) {
          $( "#calc-gauss-input" ).val(ui.value);
          gauss_handler(event);
        }
        });#}
    $( "#slider-gauss" ).slider({ value: {{gauss_default}}, min: 0, max: 2*{{modulus}}, step: 1,
        change: function( event, ui ) {
          $( "#calc-gauss-input" ).val(ui.value);
          gauss_handler(event);
        }
    });

    function jacobi_slider_handler(event, ui) {
      var b = $("#slider-jacobi-b").slider("value");
      $( "#calc-jacobi-input" ).val(b);
      jacobi_handler(event);
                                                };

    $( "#slider-jacobi-b").slider({ value: {{jacobi_default}}, min: 0, max: {{eulerphi}}, step: 1,
        change: function( event, ui ) {
            $( "#calc-jacobi-input" ).val(ui.value);
            jacobi_handler(event);
        }
     });

    function kloosterman_slider_handler(event, ui) {
      var a = $("#slider-kloosterman-a").slider("value");
      var b = $("#slider-kloosterman-b").slider("value");
      $( "#calc-kloosterman-input" ).val(""+a+","+b);
      kloosterman_handler(event);
    }; 

    $( "#slider-kloosterman-a" ).slider({ value: {{kloosterman_default_a}}, min: 0, max: 2*{{modulus}}, step: 1,
      change: function( event, ui ) {
        kloosterman_slider_handler(event, ui);
       }
     });

    $( "#slider-kloosterman-b" ).slider({ value: {{kloosterman_default_b}}, min: 0, max: 2*{{modulus}}, step: 1,
      change: function( event, ui ) {
        kloosterman_slider_handler(event, ui);
      }
     });

});
</script>
{% endblock %}

